package interviewProgram50._7_charNumbers;

import java.util.Scanner;

/**
 * @author 许群星
 * @decription  TODO 未完成 仍待完成
 * @data 2020/2/1720:37
 **/
public class CharNumbers {
    public static void main(String[] args) {

        //输入字符串
        System.out.println("请输入字符串，回车结束：");
        Scanner scanner = new Scanner(System.in);
        String string = scanner.nextLine();
        scanner.close();

        count(string);
    }

    /**
     * 字符个数
     *
     * @param string
     */
    private static void count(String string) {
        String E1 = "[\u4e00-\u9fa5]"; //汉字
        String E2 = "[a-zA-Z]";
        String E3 = "[0-9]";
        String E4 = "\\s";   //空格
        int countChinese = 0, countLetter = 0, countNumber = 0, countSpace = 0, countOther = 0;

        char[] arrayChar = string.toCharArray();  //字符串转为字符数组
        String[] arrayString = new String[arrayChar.length];//汉字只能作为字符串处理

        for (int i = 0; i < arrayChar.length; i++) {
            arrayString[i] = String.valueOf(arrayChar[i]);
            //遍历数组中的元素
            for (String s : arrayString) {
                if (s.matches(E1))
                    countChinese++;
                else if (s.matches(E2))
                    countLetter++;
                else if (s.matches(E3))
                    countNumber++;
                else if (s.matches(E4))
                    countSpace++;
                else
                    countOther++;
            }

            System.out.println("输入汉字的个数为" + countChinese);
            System.out.println("输入字母的个数为" + countLetter);
            System.out.println("输入数字的个数为" + countNumber);
            System.out.println("输入空格的个数为" + countSpace);
            System.out.println("输入其他的个数为" + countOther);
        }
    }
}
